package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.app.Dialog;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.FKnowAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.FKnowBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.FKnowListModel;

public class FKnowListActivity extends BaseActivity {
    private EmptyRecyclerView fknow_recycle;
    private List<FKnowBean> items;
    ImageView fknowlist_fh;
    TextView fknowlist_title;
    private String title;
    View fknowlist_ev;
    private Dialog mDialog;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_fknow_list);
        fknow_recycle = (EmptyRecyclerView)findViewById(R.id.fknow_recycle);
        fknowlist_fh = (ImageView)findViewById(R.id.fknowlist_fh);
        fknowlist_title = (TextView) findViewById(R.id.fknowlist_title);
        fknowlist_ev = (View)findViewById(R.id.fknowlist_ev);
        title = getIntent().getStringExtra("title");
        fknowlist_title.setText(title);
        mDialog = WeiboDialogUtils.createLoadingDialog(FKnowListActivity.this, "获取中...");
        FKnowListModel fKnowListModel=new FKnowListModel();
        fKnowListModel.getFknowList(title,fKnowBeanListListener);
    }

    @Override
    void initEvent() {
        fknowlist_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initDate() {

    }

    ListListener<FKnowBean> fKnowBeanListListener = new ListListener<FKnowBean>() {
        @Override
        public void onResponse(List<FKnowBean> list) {

            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(FKnowListActivity.this);
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            fknow_recycle.setLayoutManager(linearLayoutManager);
            items=list;
            FKnowAdapter fKnowAdapter=new FKnowAdapter(FKnowListActivity.this,items,R.layout.modeuleitem);
            fknow_recycle.setAdapter(fKnowAdapter);
            fknow_recycle.setItemAnimator(new DefaultItemAnimator());
            fknow_recycle.setEmptyView(fknowlist_ev);
            DialogThridUtils.closeDialog(mDialog);

        }

        @Override
        public void onFail(String msg) {
           // Toast.makeText(FKnowListActivity.this,"1",Toast.LENGTH_SHORT).show();
            DialogThridUtils.closeDialog(mDialog);
        }
    };
}
